﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MedicViet.Models;

namespace MedicViet.Controllers
{
    public class ContactController : Controller
    {
        private MedicVietEntities db = new MedicVietEntities();

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(Feedback feedback)
        {

            if (ModelState.IsValid)
            {
                db.Feedbacks.AddObject(feedback);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(feedback);
        }

        public ViewResult Details(int id)
        {
            Feedback feedback = db.Feedbacks.Single(f => f.id == id);
            return View(feedback);
        }

        public ActionResult Delete(int id)
        {
            Feedback feedback = db.Feedbacks.Single(f => f.id == id);
            return View(feedback);
        }

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            Feedback feedback = db.Feedbacks.Single(f => f.id == id);
            db.Feedbacks.DeleteObject(feedback);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}